package day11.task;


import java.util.*;

public class TaskThree {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<String, Integer> attendance = new HashMap<>();
        // 读取输入
        while (true) {
            String line = scanner.nextLine();
            if (line.equals("end")) {
                break;
            }
            String[] employees = line.split("\\s+");

            // 更新员工的出勤次数
            for (String employee : employees) {
                attendance.put(employee, attendance.getOrDefault(employee, 0) + 1);
            }
        }
        // 按照要求进行排序输出
        List<Map.Entry<String, Integer>> sortedAttendance = new ArrayList<>(attendance.entrySet());
        sortedAttendance.sort((a, b) -> {
            if (a.getValue().equals(b.getValue())) {
                return 0;
            }
            return b.getValue().compareTo(a.getValue());
        });
        // 输出结果
        for (Map.Entry<String, Integer> entry : sortedAttendance) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}
